package algorithm.dynamicProgramming.fibonacci;

import java.util.Arrays;

/**
 * @Author CandyWall
 * @Date 2021/4/5--21:25
 * @Description 斐波那契
 */
public class Fibonacci_v2 {
    private static int[] memo;
    private static int num;
    private static int fib(int n) {
        num++;
        memo[0] = 0;
        memo[1] = 1;
        for (int i = 2; i <= n; i++) {
            memo[i] = memo[i - 2] + memo[i - 1];
        }
        return memo[n];
    }
    public static void main(String[] args) {
        int n = 10000;
        memo = new int[n + 1];
        Arrays.fill(memo, -1);
        long start = System.nanoTime();
        System.out.println(fib(n));
        System.out.println("耗时：" + ((System.nanoTime() - start) * 1.0 / 1000_000) + " ms");
        System.out.println("共调用 " + num + " 次");
    }
}
